package com.gzgy.ustore.api.filter;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;

import javax.annotation.PostConstruct;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.gzgy.ustore.api.web.view.SensitiveWordsVO;

@Component
public class WordsFilter {
	
    private static Log log = LogFactory.getLog(WordsFilter.class);
    public static WordsFilter wmParser= new WordsFilter();;
    private static String CHARSET = "utf-8";
    private boolean initFlag = false;
    //private UnionPatternSet unionPatternSet = new UnionPatternSet();
    private int maxIndex = (int) java.lang.Math.pow(2, 16);
    private int shiftTable[] = new int[maxIndex];
    public Vector<Vector<AtomicPattern>> hashTable = new Vector<Vector<AtomicPattern>>();
    private UnionPatternSet tmpUnionPatternSet = new UnionPatternSet();
    private static String textFilter="";
    
    static{
    	textFilter="59646666\r\n86069961\r\n164067023\r\n2962293161\r\n2962297268\r\n2962297398\r\n13031089912\r\n13102046979\r\n13146488142\r\n13153267960\r\n13175570559\r\n13302086777\r\n13311561158\r\n13327461186\r\n13366667562\r\n13382181067\r\n13401089976\r\n13404331218\r\n13410669667\r\n13425179050\r\n13459110385\r\n13466551980\r\n13466576972\r\n13512163452\r\n13514251417\r\n13521437151\r\n13552681239\r\n13552750746\r\n13573358946\r\n13582359646\r\n13601254962\r\n13614710145\r\n13621734666\r\n13623419883\r\n13625813927\r\n13652020218\r\n13666312323\r\n13684935623\r\n13770289999\r\n13776327659\r\n13790725745\r\n13810158023\r\n13810204393\r\n13810503199\r\n13813992858\r\n13820955388\r\n13823133938\r\n13826116553\r\n13852536878\r\n13901075937\r\n13905337703\r\n13906281237\r\n13909850925\r\n13911631375\r\n13924674472\r\n13959115297\r\n13959185076\r\n13964863802\r\n13968335030\r\n13969108011\r\n13969650133\r\n15010031663\r\n15010357930\r\n15011599039\r\n15032793119\r\n15054266186\r\n15111216331\r\n15116206626\r\n15142529188\r\n15166611376\r\n15299079671\r\n15800563733\r\n15801582836\r\n15801624903\r\n15801644872\r\n15803419315\r\n15811220438\r\n15840103911\r\n15860054411\r\n15878755201\r\n15880002010\r\n15900978505\r\n15901068901\r\n15935133659\r\n15940885150\r\n15950553407\r\n18601124005\r\n18601161525\r\n18610056869\r\n18616330065\r\n18622096677\r\n18622119612\r\n18776882609\r\n18953233730\r\n18957114952\r\n18957867313\r\n18992850478\r\n51085546923\r\n51085546948\r\n57783632851\r\n1070000000000\r\n嘛.批 卖.逼 5毛\"\r\n嘛.批\r\n死肥婆 死肥佬 死胖 肥婆 肥佬\r\n(025)6866`2852\r\n：68223183\r\n：68893123\r\n[彩].{0,4}[民]\r\n“砸金蛋”\r\n《中.国.建.行》\r\n《中国建行》\r\n【澳西奴】\r\n【工行】\r\n【建 设 银 行】\r\n☆☆☆尊敬的用户\r\n010-5129 370\r\n010-51293704\r\n010-51296471\r\n021-29064171\r\n021-29064205\r\n021-29064207\r\n021-60512387\r\n021-60512629\r\n025-58910570\r\n025-58910729\r\n025-58946823\r\n025-58946916\r\n025-66706013\r\n025-66709013\r\n025-66709276\r\n025-68662303\r\n025-68662732\r\n025-68662841\r\n025-68662852\r\n025-68662943\r\n025-68663465\r\n025-85946823\r\n025-85946916\r\n027-51511923\r\n027-51511952\r\n028-66004825\r\n028-66008042\r\n028-66771104\r\n028-66771124\r\n028-66771134\r\n028-68223156\r\n028-68665029\r\n028-68665255\r\n028-68665635\r\n028-68665636\r\n028-68665823\r\n028-68802072\r\n028-68803016\r\n028-68803180\r\n028-68803230\r\n028-68893769\r\n028-68895089\r\n029-62290747\r\n029-82083985\r\n0371-61630239\r\n0371-61673856\r\n0371-61673916\r\n0371-6167391温\r\n0371-61675193\r\n0371-61675277\r\n0371-61675287\r\n0371-61675806\r\n0371-61821103\r\n0371-61821201\r\n0371-61821212\r\n0371-61821287\r\n0371-66857330\r\n0371-66857730\r\n0398-7897291\r\n0398-8617006\r\n0398-8685965\r\n0398-8814338\r\n0398-8893980\r\n0512-82190107\r\n0512-82190693\r\n0512-82190882\r\n0512-82190939\r\n0516-83629052\r\n0516-83629126\r\n0516-83629241\r\n0516-83629732\r\n0571--【工行\r\n0571-65112687\r\n0571-65113663\r\n0571-82073573\r\n0571-89073573\r\n0571-8911-【工行\r\n0571-89113795\r\n0571-89118097\r\n0571-89119063\r\n0571-89119515\r\n0571-89119559\r\n0571-89119763\r\n0571-89119772\r\n0571-89119795\r\n0571-89119901\r\n0571-8911991-\r\n0571-89213573\r\n0571-89215318\r\n0574-66105790\r\n0574-81202279\r\n057481210295-\r\n0574-81210295\r\n0574-82280-【工\r\n0574-82280256\r\n0574-82280265\r\n0574-82280526\r\n0574-82280626\r\n0574-82280797\r\n0577-8363-285\r\n0731-86605359\r\n0731-86607491\r\n0752-3515619\r\n0752-3570976\r\n0752-3573661\r\n0752-3592416\r\n0898--【工 行\r\n0898--【工 商 银\r\n0898--【工行\r\n0898--【工商银\r\n0898-00-【工行\r\n0898-10-【工行\r\n0898-111-【工行\r\n0898-2363\r\n0898-68922363\r\n0898-69032943\r\n0898-69056191\r\n0898-69101125\r\n0898-69101137\r\n0898-69201137\r\n0898-69260865\r\n0898-69266191\r\n0898-69551620\r\n0898-69562590\r\n0898-69822363\r\n0991-2162951\r\n0991-5706237\r\n0991-5706895\r\n0991-5706896\r\n0991-5706908\r\n0991-5706909\r\n0991-5706910\r\n0991-5707659\r\n0991-8368120\r\n0991-8368130\r\n0991-8368132\r\n0991-8368162\r\n1 3 0\r\n1 3 3\r\n16大\r\n18box\r\n21世纪中国基金会\r\n3级片\r\n400-6268205\r\n400-6268205-\r\n400-6366939\r\n400-6366-939\r\n400-636-6939\r\n400-6666-817\r\n400-6768328\r\n400-6863969\r\n4006-979796\r\n4006-999-757\r\n5000元=60000条短信＋赠送500元手机充值卡\r\n56.com\r\n5d6d\r\n6-4tianwang\r\n6-4tianwang\r\n7787.bbs.vg\r\n7k.0033.cn\r\n82660.com\r\n89-64cdjp\r\nAAA级\r\nav\r\nA级\r\nA片\r\nbaidugoogle\r\nbignews\r\nbitch\r\nboxun\r\nB贱\r\nB样\r\nB装\r\ncctvdan.com\r\nchinaliberal\r\nchinamz\r\nchinesenewsnet\r\nchun药\r\ncnd\r\ncntvdan.com\r\ncpiu\r\ncreaders\r\ndafa\r\ndajiyuan\r\ndfdz\r\nDICK\r\ndpp\r\neasou\r\nfalu\r\nfalun\r\nfalundafa\r\nfa伦功\r\nfa轮\r\nflamesky\r\nflg\r\nfreechina\r\nfreedom\r\nfreenet\r\nfuck\r\ngcd\r\nhengjian\r\nhongzhi\r\nhrichina\r\nhttp\r\nhttp://card.cd/Ovwjmz4AAZ8.s\r\nhttp://tx.com.cn\r\nhttp://tx.com.cn/\r\nhuanet\r\nhxzi\r\nhypermart.net\r\nincest\r\nJB\r\njiangdongriji\r\njtyl\r\nlei8\r\nlihongzhi\r\nmaking\r\nminghui\r\nminghuinews\r\nmmxdd\r\nmofile\r\nmoli\r\nnacb\r\nnaive\r\nnmis\r\npaper64\r\npeacehall\r\nplayboy\r\nrenminbao\r\nrenmingbao\r\nrfa\r\nrjzj\r\ns3x6\r\nsafeweb\r\nsex\r\nsimple\r\nSM\r\nSoccer01.com\r\nsvdc\r\ntaip\r\ntibetalk\r\ntriangle\r\ntriangleboy\r\nUltraSurf\r\nunixbox\r\nustibet\r\nvoa\r\nvoachinese\r\nwangce\r\nwebng\r\nwoe\r\nwstaiji\r\nwww.288548.com\r\nxinsheng\r\nyuming\r\nzhengjian\r\nzhengjianwang\r\nzhenshanren\r\nzhuanfalun\r\nzzzg\r\n爱液\r\n安全局\r\n澳西奴\r\n八九\r\n八老\r\n巴赫\r\n罢工\r\n罢课\r\n白立朴\r\n白梦\r\n白皮书\r\n包你英年早逝\r\n包皮\r\n办证\r\n保钓\r\n报警\r\n鲍戈\r\n鲍彤\r\n暴乱\r\n暴政\r\n北大三角地论坛\r\n北高联\r\n北韩\r\n北京当局\r\n北京之春\r\n北美自由论坛\r\n贝领\r\n被插\r\n被盗\r\n本行即将在您的帐内划走\r\n笨逼\r\n屄\r\n逼毛\r\n别墅\r\n不得好死\r\n彩民\r\n蔡崇国\r\n藏独\r\n操.你.妈.的千千万\r\n操.你.娘\r\n操蛋\r\n操了\r\n操你姐\r\n操你妈逼\r\n操你妈比\r\n操你妈\r\n曹刚川\r\n曹长青\r\n草你\r\n草你妈妈\r\n肏\r\n曾培炎\r\n曾庆红\r\n曾荫权\r\n插进\r\n插我\r\n柴玲\r\n常劲\r\n车仑\r\n陈炳基\r\n陈军\r\n陈良宇\r\n陈蒙\r\n陈破空\r\n陈水扁\r\n水扁\r\n陈希同\r\n陈小同\r\n陈宣良\r\n陈一谘\r\n陈总统\r\n成人游戏\r\n成人书库\r\n程凯\r\n程铁军\r\n程真\r\n迟浩田\r\n持不同政见\r\n赤匪\r\n赤化\r\n赤裸\r\n冲击\r\n冲突\r\n抽插\r\n臭逼\r\n出卖\r\n初夜\r\n处女\r\n处女膜\r\n床上功夫\r\n吹喇叭\r\n春夏自由论坛\r\n春药\r\n刺激\r\n从您名下账上结算出￥一千元年费\r\n达赖\r\n打倒\r\n打炮\r\n大比\r\n大参考\r\n大法\r\n大花逼\r\n大纪元新闻网\r\n大纪园\r\n大家论坛\r\n大陆当局\r\n大史\r\n大史记\r\n大史纪\r\n大血B\r\n大中国论坛\r\n大中华论坛\r\n大众真人真事\r\n代办\r\n代办证件\r\n贷款\r\n戴相龙\r\n党棍\r\n党国\r\n荡妇\r\n倒台\r\n登辉\r\n等奖幸运观众\r\n等奖验证码\r\n邓小平\r\n邓笑贫\r\n低息\r\n迪里夏提\r\n抵押\r\n抵制日货\r\n地产\r\n地下教会\r\n地下刊物\r\n电视流氓\r\n钓鱼岛\r\n丁关根\r\n丁元\r\n丁子霖\r\n东北独立\r\n东方红时空\r\n东方时空\r\n东南西北论谈\r\n东社\r\n东突\r\n东突厥斯坦\r\n东土耳其斯坦\r\n东西南北论坛\r\n董建华\r\n动乱\r\n恫体\r\n胴体\r\n独裁\r\n独裁政治\r\n独夫\r\n独立台湾会\r\n独院\r\n杜智富\r\n短信中心\r\n多维\r\n屙民\r\n俄国\r\n恶警\r\n二B\r\n二逼\r\n二奶\r\n发.春\r\n发春\r\n发愣\r\n发抡功\r\n发论公\r\n发送100%到达\r\n发正念\r\n法*功\r\n法*轮*功\r\n法.轮.功\r\n法[轮伦]\r\n法lun功\r\n法愣\r\n法抡\r\n法抡功\r\n法仑\r\n法伦\r\n法囵\r\n法沦\r\n法纶\r\n法轮\r\n法轮功\r\n法论\r\n法十轮十功\r\n法谪\r\n法谪功\r\n反动\r\n反封锁技术\r\n反腐败论坛\r\n反革命\r\n反华\r\n反攻\r\n反攻大陆\r\n反共\r\n反人类\r\n反日\r\n反社会\r\n方励之\r\n方舟子\r\n房产\r\n飞扬论坛\r\n非常6 1\r\n非常6加1\r\n非常6加1场外活动\r\n肥佬\r\n肥婆\r\n斐得勒\r\n费良勇\r\n分家在\r\n分裂\r\n粉嫩\r\n粉饰太平\r\n风雨神州\r\n风雨神州论坛\r\n封从德\r\n封杀\r\n杀人\r\n谋杀\r\n冯东海\r\n冯素英\r\n佛展千手法\r\n服：66008843\r\n服：66009304\r\n服：66009403\r\n服：68665155\r\n服：68665955\r\n服：86069935\r\n服：86069961\r\n付申奇\r\n傅申奇\r\n傅志寰\r\n干柴烈火\r\n干拎娘\r\n干你\r\n干你娘\r\n干女\r\n干七八\r\n肛\r\n肛交\r\n肛门\r\n高潮\r\n高官\r\n高文谦\r\n高薪养廉\r\n高干子弟\r\n高自联\r\n睾丸\r\n搞B\r\n戈扬\r\n鸽派\r\n歌功颂德\r\n个人崇拜\r\n给脸不要脸\r\n工行信使\r\n工自联\r\n公寓\r\n功法\r\n功友\r\n共产\r\n共产党\r\n共党\r\n共匪\r\n共狗\r\n共军\r\n共青团\r\n勾引\r\n狗逼\r\n狗B\r\n狗比\r\n狗卵子\r\n狗屎\r\n关卓中\r\n贯通两极法\r\n广闻\r\n滚蛋\r\n郭伯雄\r\n郭罗基\r\n郭平\r\n郭岩华\r\n国家安全\r\n国家机密\r\n国军\r\n国民党\r\n国研新闻邮件\r\n国贼\r\n哈.嘛.批\r\n哈.批\r\n蛤蟆\r\n海龙大厦\r\n韩东方\r\n韩联潮\r\n汉奸\r\n通奸\r\n好色\r\n何德普\r\n何清涟\r\n何勇\r\n和你妈搞\r\n河殇\r\n黑马\r\n黑庄\r\n红灯区\r\n红色恐怖\r\n红志\r\n宏恩\r\n宏法\r\n洪传\r\n洪吟\r\n洪哲胜\r\n洪志\r\n洪治\r\n胡紧掏\r\n胡锦涛\r\n胡锦滔\r\n胡锦淘\r\n胡景涛\r\n胡平\r\n胡总书记\r\n护法\r\n花B\r\n花花公子\r\n华建敏\r\n华通时事论坛\r\n华夏文摘\r\n华语世界论坛\r\n华岳\r\n华岳时事论坛\r\n怀春\r\n换妻\r\n黄片\r\n黄慈萍\r\n黄祸\r\n黄菊\r\n黄色电影\r\n黄网\r\n黄翔\r\n回报\r\n回教\r\n回民暴\r\n回民暴动\r\n回族\r\n悔过书\r\n毁你\r\n活不下去\r\n活佛\r\n获利\r\n机八\r\n机巴\r\n鸡8\r\n鸡八\r\n鸡巴\r\n鸡扒\r\n鸡叭\r\n鸡芭\r\n鸡吧\r\n鸡掰\r\n鸡鸡\r\n鸡毛信文汇\r\n积克馆\r\n姬胜德\r\n基本法\r\n基督\r\n激情\r\n极品推荐\r\n即把\r\n妓.院\r\n妓[男女院]\r\n妓女\r\n妓院\r\n寂寞美女\r\n家教\r\n贾庆林\r\n贾廷安\r\n贾育台\r\n价格6分到8分\r\n奸\r\n奸淫\r\n建 设 银 行\r\n建`行\r\n建仓\r\n建国党\r\n贱\r\n贱.B\r\n贱.人\r\n贱B\r\n贱逼\r\n贱比\r\n贱货\r\n贱人\r\n江core\r\n江ze民\r\n江八点\r\n江独裁\r\n江锦恒\r\n江流氓\r\n江罗\r\n江绵恒\r\n江青\r\n江戏子\r\n江则民\r\n江泽慧\r\n江泽民\r\n江澤民\r\n江贼\r\n江贼民\r\n江猪\r\n江猪媳\r\n江主席\r\n将从您卡上划走￥1200\r\n将从您账户中支出1200元\r\n将则民\r\n姜春云\r\n僵贼\r\n僵贼民\r\n疆独\r\n讲法\r\n交班\r\n焦国标\r\n教徒\r\n教养院\r\n接班\r\n揭批书\r\n借贷\r\n借款\r\n今日布局\r\n今日建仓\r\n今天布局\r\n今天建仓\r\n金尧如\r\n禁看\r\n京官治港\r\n经文\r\n精液\r\n靖国神社\r\n静坐\r\n九.评\r\n九评\r\n九-评\r\n巨乳\r\n开苞\r\n开放杂志\r\n看中国\r\n抗议\r\n靠腰\r\n客服:66008843\r\n客服:86069961\r\n客服:86069972\r\n客服务：68665955\r\n口交\r\n狂操\r\n狂摸\r\n邝锦文\r\n垃.圾\r\n拉丹\r\n拉登\r\n拉升\r\n烂B\r\n烂逼\r\n烂比\r\n烂货\r\n烂批\r\n狼人\r\n浪女\r\n劳动教养所\r\n劳改\r\n劳教\r\n老江\r\n老毛\r\n老人政治\r\n老子 操.你.妈\r\n黎安友\r\n李大师\r\n李登辉\r\n李红痔\r\n李宏志\r\n李洪宽\r\n李洪志\r\n李继耐\r\n李兰菊\r\n李岚清\r\n李老师\r\n李录\r\n李禄\r\n李瑞环\r\n李少民\r\n李淑娴\r\n李旺阳\r\n李文斌\r\n李小朋\r\n李小鹏\r\n李月月鸟\r\n李长春\r\n李志绥\r\n李驻铭\r\n李总理\r\n李总统\r\n利率\r\n利息\r\n连胜德\r\n联总\r\n联总之声\r\n联总之声传单\r\n廉政大论坛\r\n炼功\r\n梁光烈\r\n梁擎墩\r\n两岸关系\r\n两岸三地论坛\r\n两个中国\r\n两会\r\n两会报道\r\n两会新闻\r\n聊天热线\r\n廖锡龙\r\n林保华\r\n林樵清\r\n林慎立\r\n林幼芳\r\n林长盛\r\n凌辱\r\n刘宾深\r\n刘宾雁\r\n刘刚\r\n刘国凯\r\n刘华清\r\n刘俊国\r\n刘凯中\r\n刘千石\r\n刘青\r\n刘山青\r\n刘士贤\r\n刘文胜\r\n刘晓波\r\n刘晓竹\r\n刘永川\r\n流亡\r\n六合彩\r\n六和彩\r\n六四\r\n六四事件\r\n龙虎豹\r\n楼宇\r\n陆委\r\n陆委会\r\n露股\r\n露乳\r\n抡功\r\n伦功\r\n轮大\r\n轮功\r\n轮奸\r\n罗干\r\n罗礼诗\r\n裸聊\r\n裸陪\r\n裸睡\r\n裸体\r\n吕京花\r\n妈勒\r\n妈了\r\n妈屁\r\n麻痹\r\n麻将机\r\n马大维\r\n马良骏\r\n马三家\r\n马时敏\r\n嘛.批 卖.逼 5毛\r\n嘛批\r\n买春\r\n卖.淫\r\n卖B\r\n卖逼\r\n卖逼养活你\r\n卖比\r\n卖春\r\n卖国\r\n卖国唐捷\r\n卖淫\r\n瞒报\r\n毛厕洞\r\n毛片\r\n毛泽东\r\n毛贼东\r\n没有此城市数据\r\n美国参考\r\n美国之音\r\n美少妇\r\n美穴\r\n美艳\r\n媚影\r\n蒙独\r\n蒙古独\r\n蒙古独立\r\n猛料\r\n迷幻药\r\n迷药\r\n密穴\r\n蜜穴\r\n绵恒\r\n免费的妓女\r\n民国\r\n民进党\r\n民联\r\n民意\r\n民意论坛\r\n民运\r\n民阵\r\n民主\r\n民主墙\r\n民族矛盾\r\n名校\r\n明慧\r\n茉 莉\r\n茉！莉\r\n茉.莉\r\n茉。莉\r\n茉/莉\r\n茉莉\r\n茉莉花\r\n莫伟强\r\n木犀地\r\n木子论坛\r\n幕后真相\r\n奶头\r\n奶子\r\n男妓\r\n男女公关\r\n南大自由论坛\r\n南华\r\n闹事\r\n內射\r\n内裤\r\n嫩B\r\n嫩穴\r\n倪育贤\r\n你.妈.卖.逼\r\n你.娘口.交\r\n你.他.妈.的\r\n你.他.娘\r\n你爸\r\n你滚好么\r\n你老母\r\n你妈\r\n你妈的\r\n你妈的逼\r\n你妈卖逼\r\n你娘\r\n你娘买逼\r\n你说我说论坛\r\n你他妈的\r\n你他娘\r\n你太.贱.了\r\n你太贱了\r\n年化收益\r\n您的个人账'户\r\n牛逼\r\n牛比\r\n拍A.片\r\n拍A片\r\n潘国平\r\n潘金莲\r\n泡沫经济\r\n喷你\r\n屁眼\r\n嫖娼\r\n嫖妓\r\n嫖宿\r\n嫖宿幼女\r\n平方\r\n破鞋\r\n齐墨\r\n祁建\r\n汽油短缺\r\n汽油飞涨\r\n千秋家园\r\n钱达\r\n钱国梁\r\n钱其琛\r\n枪\r\n枪枝\r\n枪决女犯\r\n强暴\r\n强奸\r\n强坚\r\n强力\r\n抢粮记\r\n乔石\r\n钦本立\r\n亲美\r\n亲日\r\n秦晋\r\n青天白日旗\r\n轻舟快讯\r\n情妇\r\n情趣\r\n情色\r\n情欲\r\n庆红\r\n去你妈的\r\n全国两会\r\n全家操一遍\r\n全裸\r\n群奸\r\n热比娅\r\n热站政论网\r\n人民大众时事参考\r\n人民内情真相\r\n人民真实\r\n人民真实报道\r\n人民之声论坛\r\n人权\r\n日你妈\r\n日内瓦金融\r\n日你\r\n融贷\r\n肉棒\r\n肉洞\r\n肉棍\r\n肉穴\r\n乳房\r\n乳娘\r\n乳头\r\n三陪\r\n三星装饰\r\n三级片\r\n氵去车仑工力\r\n丧心病狂\r\n骚\r\n骚货\r\n大学骚乱\r\n骚乱\r\n高校骚乱\r\n色狐\r\n色虎\r\n色狼\r\n色情\r\n杀笔\r\n杀你\r\n傻B\r\n傻逼\r\n傻比\r\n傻冒\r\n傻帽\r\n煞笔\r\n上海帮\r\n上海孤儿院\r\n少妇\r\n邵家健\r\n绍兴万千百货\r\n蛇蝎女人\r\n社会主义\r\n口活\r\n射精\r\n涉日\r\n神通加持法\r\n沈彤\r\n升天\r\n生殖器\r\n盛华仁\r\n盛雪\r\n失密\r\n石戈\r\n时代论坛\r\n时事参考\r\n时事论坛\r\n实惠套餐\r\n示威\r\n世界经济导报\r\n市工联\r\n事实独立\r\n是狗养的\r\n收容所\r\n首查\r\n首付\r\n兽交\r\n熟女\r\n数据中国\r\n刷喇叭\r\n双十节\r\n水扁\r\n税力\r\n司马晋\r\n司马璐\r\n司徒华\r\n私幕\r\n斯诺\r\n死GD\r\n死GM\r\n死爸\r\n死肥佬\r\n死肥婆\r\n鲍戈\r\n死垃.圾\r\n死妈\r\n死胖\r\n死骗子\r\n死全家\r\n四川独立\r\n宋xx\r\n宋平\r\n宋书元\r\n宋祖英\r\n苏绍智\r\n苏晓康\r\n他妈\r\n他妈的\r\n他母亲\r\n它妈\r\n她妈\r\n她水流\r\n台独\r\n台海\r\n台盟\r\n台湾\r\n台湾独\r\n台湾独立\r\n台湾狗\r\n台湾建国运动组织\r\n台湾陆委会\r\n台湾青年独立联盟\r\n台湾政论区\r\n台湾自由联盟\r\n太.贱.了\r\n太监\r\n太贱了\r\n太子党\r\n汤光中\r\n唐柏桥\r\n唐捷\r\n陶驷驹\r\n套牌\r\n特首\r\n特招班\r\n滕文生\r\n天安门\r\n天安门录影带\r\n天安门事件\r\n天安门屠杀\r\n天安门一代\r\n天怒\r\n天下网\r\n天葬\r\n舔\r\n同性\r\n同志\r\n童屹\r\n统独\r\n统独论坛\r\n统战\r\n捅你姐肛门\r\n偷欢\r\n偷拍\r\n投胎\r\n投资\r\n突厥斯坦\r\n屠杀\r\n推翻\r\n脱党\r\n脱光\r\n脱裤\r\n唾弃\r\n外交论坛\r\n外交与方略\r\n玩到床\r\n晚年周恩来\r\n万科\r\n万润南\r\n万维读者论坛\r\n万晓东\r\n汪岷\r\n亡党\r\n王宝森\r\n王炳章\r\n王策\r\n王超华\r\n王丹\r\n王辅臣\r\n王刚\r\n王涵万\r\n王沪宁\r\n王军涛\r\n王力雄\r\n王瑞林\r\n王润生\r\n王若望\r\n王希哲\r\n王秀丽\r\n王冶坪\r\n网特\r\n维勒\r\n尉健行\r\n魏京生\r\n魏新生\r\n温家宝\r\n温元凯\r\n文革\r\n我.操.你.妈\r\n我.日.你.妈\r\n我操\r\n我操你\r\n我操你妈\r\n我草\r\n我行即将在您的卡上\r\n我'行将从您的卡'里扣除\r\n我'行将从您的卡'里扣除￥1300\r\n我行将从您卡上划走\r\n我行将从您卡上支出\r\n我行将从您卡上支出1200元\r\n我行将于次日从您卡上\r\n我行将于次日从您卡上支出一千元年费\r\n我行将在您的卡上扣取\r\n我行已成功从您的卡上\r\n我行已成功在您卡上扣除\r\n我行已在您办理的卡中扣除\r\n我行已在您卡中减退\r\n我行已在您卡中扣除\r\n我日\r\n我日你妈\r\n无界浏览器\r\n吾尔开希\r\n吴百益\r\n吴邦国\r\n吴方城\r\n吴官正\r\n吴弘达\r\n吴宏达\r\n吴仁华\r\n吴学灿\r\n吴学璨\r\n五不\r\n伍凡\r\n西藏独\r\n西藏独立\r\n西藏喇嘛\r\n习近平\r\n洗脑\r\n下身\r\n下体\r\n详询:66008843\r\n详询：86069961\r\n项怀诚\r\n项怀城\r\n项小吉\r\n肖强\r\n小参考\r\n小洞\r\n小额贷款\r\n小肛\r\nK房小姐\r\n小穴\r\n邪恶\r\n泄密\r\n谢选骏\r\n谢长廷\r\n谢中之\r\n辛灏年\r\n新观察论坛\r\n新华举报\r\n新华内情\r\n新华通论坛\r\n新疆独\r\n新疆独立\r\n新生网\r\n新闻封锁\r\n新语丝\r\n信贷\r\n信用危机\r\n邢铮\r\n性v爱\r\n性爱\r\n性伴侣\r\n性感\r\n性行为\r\n性狐\r\n性交\r\n性生活\r\n性欲\r\n性姿势\r\n熊炎\r\n熊焱\r\n修炼\r\n修炼者\r\n徐邦秦\r\n徐才厚\r\n徐匡迪\r\n徐水良\r\n许家屯\r\n薛伟\r\n学潮\r\n学联\r\n学习班\r\n学运\r\n学自联\r\n雪山狮子\r\n丫挺\r\n丫挺的\r\n丫头\r\n严家其\r\n严家祺\r\n阎明复\r\n颜射\r\n口暴\r\n口爆\r\n艳情\r\n艳舞\r\n央视内部晚会\r\n阳毛\r\n杨怀安\r\n杨建利\r\n杨巍\r\n杨月清\r\n杨周\r\n洋房\r\n姚月谦\r\n叶杭雪\r\n叶语雪\r\n夜话紫禁城\r\n一手遮天\r\n一丝不挂\r\n一夜\r\n一中一台\r\n伊斯兰\r\n伊斯兰运动\r\n移民\r\n义解\r\n亦凡\r\n异见人士\r\n异议人士\r\n易丹轩\r\n易志熹\r\n阴[部道]\r\n阴部\r\n阴唇\r\n阴到\r\n阴道\r\n阴蒂\r\n阴茎\r\n阴胫\r\n阴毛\r\n阴水\r\n阴啼\r\n阴穴\r\n银 行 承 兑 汇 票 兑现\r\n淫\r\n淫荡\r\n淫秽\r\n淫乱\r\n淫水\r\n淫穴\r\n尹庆民\r\n印尼伊斯兰祈祷团\r\n由喜贵\r\n游行\r\n手淫\r\n打飞机\r\n幼齿\r\n幼女\r\n于大海\r\n于浩成\r\n余英时\r\n舆论反制\r\n摇头丸\r\n毒品\r\n冰毒\r\nK粉\r\n性病\r\n梅毒\r\n淋病\r\n老军医\r\n宇明网\r\n药家鑫\r\n欲火\r\n圆满\r\n远志明\r\n岳武\r\n砸蛋\r\n砸蛋活动\r\n砸金蛋\r\n在国美刷卡消费5000元\r\n在十月\r\n造反\r\n则民\r\n择民\r\n泽民\r\n贼民\r\n诈骗\r\n张伯笠\r\n张钢\r\n张宏堡\r\n张健\r\n张京生\r\n张林\r\n张万年\r\n张伟国\r\n张昭富\r\n张志清\r\n涨停\r\n招妓\r\n招聘\r\n赵海青\r\n赵南\r\n赵品潞\r\n赵晓微\r\n赵紫阳\r\n哲民\r\n真相\r\n真象\r\n镇压\r\n争鸣论坛\r\n正见网\r\n正义党论坛\r\n郑义\r\n郑源\r\n政变\r\n政权\r\n政治反对派\r\n政治犯\r\n政治风波\r\n支那\r\n鼅\r\n直选\r\n指点江山论坛\r\n中俄边界\r\n中功\r\n中共\r\n中共当局\r\n中共中央\r\n中国《建行》\r\n中国电信\r\n中国复兴论坛\r\n中国孤儿院\r\n中国和平\r\n中国论坛\r\n中国社会进步党\r\n中国社会论坛\r\n中国威胁论\r\n中国问题论坛\r\n中国移动通信\r\n中国真实内容\r\n中国之春\r\n中国猪\r\n中华大地\r\n中华大众\r\n中华讲清\r\n中华人民实话实说\r\n中华人民正邪\r\n中华时事\r\n中华养生益智功\r\n中华真实报道\r\n中央军委\r\n钟山风雨论坛\r\n周锋锁\r\n周天法\r\n周旋\r\n朱嘉明\r\n朱琳\r\n朱毛\r\n朱容基\r\n朱溶剂\r\n朱镕基\r\n珠海天禾\r\n猪聋畸\r\n猪毛\r\n猪毛1\r\n主义\r\n助师世间行\r\n专制\r\n转法\r\n转化\r\n装 修\r\n装B\r\n装逼\r\n装纯\r\n装修\r\n资本主义\r\n资产\r\n资金\r\n紫星阁\r\n自民党\r\n自摸\r\n自慰\r\n自杀\r\n自杀手册\r\n自杀指南\r\n自由民主论坛\r\n自由运动\r\n宗共\r\n走光\r\n走私\r\n罪魁\r\n尊敬的`用户\r\n尊敬的工`行客户\r\n阝月\r\n作爱\r\n作秀\r\n做爱\r\nshit\r\nerotic\r\ndildo\r\n办证\r\ndfdz\r\ndajiyuan\r\ndafa\r\nfa轮\r\nchinesenewsnet\r\nchinamz\r\nchinaliberal\r\nB样\r\nboxun\r\nblowjob\r\nbitch\r\nbigbowl\r\nAV片\r\nAV女\r\nareunder\r\n6-4tianwang\r\n610洗脑班\r\n3P\r\nlihongzhi\r\nLesbian\r\nJ巴\r\njiangdongriji\r\nhypermart.net\r\nhuanet\r\nhrichina\r\nhongzhi\r\nHardcore\r\ngcd\r\nfalu\r\nfalun\r\nfalundafa\r\nfilter_word\r\nflg\r\nfreechina\r\nfuck\r\ngay\r\nincest\r\ntriangle\r\ntibetalk\r\ntaip\r\nsvdc\r\nstriptease\r\nrfa\r\nrenmingbao\r\nrenminbao\r\npussy\r\nPORN\r\nplayboy\r\npenis\r\npeacehall\r\npaper64\r\noralsex\r\nnude\r\nnmis\r\nminghui\r\nminghuinews\r\nnacb\r\nnaive\r\nnipple\r\nsafeweb\r\nsemen\r\nsex\r\nSlut\r\nsoftcore\r\ntriangleboy\r\ntxwq.net\r\nunixbox\r\nUltraSurf\r\nustibet\r\nvagina\r\nvoa\r\nvoachinese\r\nvoyeur\r\nwangce\r\nwstaiji\r\nxinsheng\r\nXXX\r\nX夜激情\r\nyuming\r\nzhuanfalun\r\n阿扁\r\n爱液\r\n安魂网\r\n暗杀\r\n八老\r\n罢课\r\n罢工\r\n白军\r\n白立朴\r\n白梦\r\n包夜\r\n报禁\r\n草榴\r\n草榴社区\r\n爱唯侦察\r\n爱唯\r\n爱唯侦查\r\n博彩\r\n赌博\r\n高利贷\r\n黑社会\r\n投毒\r\n叫床\r\n叫春\r\n中出\r\n内射\r\n春药\r\n出售假币\r\n强效失忆药\r\n迷奸药\r\n迷奸\r\n迷魂药\r\n迷昏药\r\n血腥图片\r\n反政府\r\n人妻\r\n群P\r\n激情视频\r\n狂插\r\n恋童\r\n恋童癖\r\n乙醚\r\n麻醉乙醚\r\n麻醉药\r\n";
    }
    @PostConstruct
    public WordsFilter getInstance() throws IOException, SQLException{
 
    	if(StringUtils.isBlank(textFilter)){
    		log.debug("Instantiating WmParser is null....");
    		return wmParser;
    	}
    	
    	try {
             log.debug("Instantiating WmParser....");
             String test=new String(textFilter.getBytes(),CHARSET);
             InputStream in = new ByteArrayInputStream(test.getBytes());
             BufferedReader reader = new BufferedReader(new InputStreamReader(in));
             String line = null;
             while ((line = reader.readLine()) != null) {
            	 wmParser.addFilterKeyWord(new String(line.getBytes(), CHARSET), 1);
             }
             reader.close();
             in.close();
    	 }catch (Exception e) {
              log.error("Exception in Instantiating WordsFilter:" + e);
              e.printStackTrace();
    	 }
        return wmParser;
    }
    
    public boolean addFilterKeyWord(String keyWord, int level) {
        if (initFlag == true)
            return false;
        UnionPattern unionPattern = new UnionPattern();
        Pattern pattern = new Pattern(keyWord);
        AtomicPattern atomicPattern = new AtomicPattern(pattern);
        unionPattern.addNewAtomicPattrn(atomicPattern);
        unionPattern.setLevel(level);
        atomicPattern.setBelongUnionPattern(unionPattern);
        tmpUnionPatternSet.addNewUnionPattrn(unionPattern);
        return true;
    }
 
    public String parse(String content, Vector<String> levelSet){
        try {
            if (initFlag == false)
                init();
            Vector<AtomicPattern> aps = new Vector<AtomicPattern>();
            StringBuilder sb = new StringBuilder();   
            char checkChar;
            for (int i = 0; i < content.length();) {
                checkChar = content.charAt(i);
                if (shiftTable[checkChar] == 0) {
                    Vector<AtomicPattern> tmpAps = new Vector<AtomicPattern>();
                    Vector<AtomicPattern> destAps = hashTable.get(checkChar);
                    int match = 0;
                    for (int j = 0; j < destAps.size(); j++) {
                        AtomicPattern ap = destAps.get(j);
                        if (ap.findMatchInString(content.substring(0, i + 1))){
                            String patternStr = ap.getPattern().getStr();
                            if (match > 0){
                                sb.setLength(sb.length() - patternStr.length());
                            } else {
                                sb.setLength(sb.length() - patternStr.length() + 1);
                            }
                            appendStar(patternStr, sb);
                            tmpAps.add(ap);
                            match++;
                        }
                    }
                    aps.addAll(tmpAps);
                    if (tmpAps.size() <= 0){
                        sb.append(checkChar);
                    }
                    i++;
                } else {
                    if (i + shiftTable[checkChar] <= content.length()){
                        sb.append(content.substring(i, i + shiftTable[checkChar]));
                    } else {
                        sb.append(content.substring(i));
                    }
                    i = i + shiftTable[checkChar];
                }
            }
            parseAtomicPatternSet(aps, levelSet);
            return sb.toString();
        } catch (Exception e) {
            log.error(e);
            e.printStackTrace();
        }
        return "";
    }
     
    private static void appendStar(String patternStr, StringBuilder sb){
        for (int c = 0;c < patternStr.length(); c++){
            char ch = patternStr.charAt(c);
            //判斷是否是中文
            if ((ch >= 0x4e00 && ch <= 0x9FA5) || (ch >= 0xF900 && ch <= 0xFA2D)){
                sb.append("＊");
            } else {
                sb.append("*");
            }
        }
    }
 
 
    private void parseAtomicPatternSet(Vector<AtomicPattern> aps,
            Vector<String> levelSet) {
        while (aps.size() > 0) {
            AtomicPattern ap = aps.get(0);
            UnionPattern up = ap.belongUnionPattern;
            if (up.isIncludeAllAp(aps)) {
                //levelSet.add(new Integer(up.getLevel()));
            	levelSet.add(up.getSet().get(0).getPattern().getStr());
            }
            aps.remove(0);
        }
    }
 
    // shift table and hash table of initialize
    private void init() {
        initFlag = true;
        for (int i = 0; i < maxIndex; i++)
        	hashTable.add(new Vector<AtomicPattern>());
        shiftTableInit();
        hashTableInit();
    }
 
    public void clear() {
        tmpUnionPatternSet.clear();
        initFlag = false;
    }
 
    private void shiftTableInit() {
        for (int i = 0; i < maxIndex; i++)
            shiftTable[i] = 2;
        Vector<UnionPattern> upSet = tmpUnionPatternSet.getSet();
        for (int i = 0; i < upSet.size(); i++) {
            Vector<AtomicPattern> apSet = upSet.get(i).getSet();
            for (int j = 0; j < apSet.size(); j++) {
                AtomicPattern ap = apSet.get(j);
                Pattern pattern = ap.getPattern();
                if (shiftTable[pattern.charAtEnd(1)] != 0)
                    shiftTable[pattern.charAtEnd(1)] = 1;
                if (shiftTable[pattern.charAtEnd(0)] != 0)
                    shiftTable[pattern.charAtEnd(0)] = 0;
            }
        }
    }
 
    private void hashTableInit() {
        Vector<UnionPattern> upSet = tmpUnionPatternSet.getSet();
        for (int i = 0; i < upSet.size(); i++) {
            Vector<AtomicPattern> apSet = upSet.get(i).getSet();
            for (int j = 0; j < apSet.size(); j++) {
                AtomicPattern ap = apSet.get(j);
                Pattern pattern = ap.getPattern();
                if (pattern.charAtEnd(0) != 0) {
                    //hashTable[pattern.charAtEnd(0)].add(ap);
                	hashTable.get(pattern.charAtEnd(0)).add(ap);
                }
            }
        }
    }
    
    /**
     * 提供給 外部調用
     * @param content
     * @return
     * @throws UnsupportedEncodingException
     */
    public static SensitiveWordsVO filterString(String content) throws UnsupportedEncodingException{
    	if(StringUtils.isBlank(content)){
    		return null;
    	}
    	Vector<String> levelSet = new Vector<String>();
    	SensitiveWordsVO vo=new SensitiveWordsVO();
    	vo.setFilterText(wmParser.parse(new String(content.getBytes(), CHARSET), levelSet));
    	Set<String> sensitiveWords=new HashSet<String>();
    	for (String string1 : levelSet) {
    		sensitiveWords.add(string1);
		}
    	vo.setSensitiveWords(sensitiveWords);
    	return vo;
    }
    
    //test function
    public static void main(String args[]) {
        try {
        	
        	WordsFilter filterEngine = new WordsFilter();//WordsFilter.getInstance();

            Vector<String> levelSet = new Vector<String>();
            String str = "单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功" +
            		"单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功" +
            		"单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功" +
            		"单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动和强奸和shit法!轮功法*轮*功";
            SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss.SSS");
            System.out.println("文本长度：" + str.length());
            System.out.println("敏感词汇总数:" + filterEngine.getInstance().tmpUnionPatternSet.getSet().size());
            Date start = new Date(System.currentTimeMillis());
            System.out.println("过滤开始：" + sf.format(start));
             
            System.out.println(str);
            System.out.println(filterEngine.getInstance().parse(new String(str.getBytes(), CHARSET), levelSet));
             
            Date end = new Date(System.currentTimeMillis());
            System.out.println("过滤完毕：" + sf.format(end));
            System.out.println("文本中出现敏感词个数：" + levelSet.size());
            System.out.println("耗时：" + (end.getTime() - start.getTime()) + "ms");
            
            System.out.println("过滤开始：" + sf.format(start));
            
            System.out.println("过convertString开始：" + filterString("单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动").getFilterText());
            System.out.println("过convertString开始：" + filterString("单个的政治，政治运动和强奸和shit法!轮功法*轮*功单个的政治，政治运动").getSensitiveWords());
        	
        } catch (Exception e) {
            e.printStackTrace();
        }
         
    }
}
 
class Pattern { // string
    Pattern(String str) {
        this.str = str;
    }
 
    public char charAtEnd(int index) {
        if (str.length() > index) {
            return str.charAt(str.length() - index - 1);
        } else
            return 0;
    }
 
    public String str;
 
    public String getStr() {
        return str;
    };
    
}
 
class AtomicPattern {
//    public boolean findMatchInString(String str) throws Exception {
//        String patStr = new String(this.pattern.str.getBytes("ISO-8859-1"), "UTF-8");
//        str = new String(str.getBytes("ISO-8859-1"), "UTF-8");
//        if (patStr.length() > str.length())
//            return false;
//        int beginIndex = str.lastIndexOf(patStr.charAt(0) + "");
//        if (beginIndex != -1){
//            String eqaulLengthStr = str.substring(beginIndex);
//            if (patStr.equalsIgnoreCase(eqaulLengthStr))
//                return true;
//        }
//        return false;
//    }
    public boolean findMatchInString(String str) {
        if (this.pattern.str.length() > str.length())
            return false;
        int beginIndex = str.lastIndexOf(this.pattern.getStr().charAt(0) + "");
        if (beginIndex != -1){
            String eqaulLengthStr = str.substring(beginIndex);
            if (this.pattern.str.equalsIgnoreCase(preConvert(eqaulLengthStr)))
                return true;
        }
        return false;
    }
    private String preConvert(String content) {
        String retStr = new String();
        for (int i = 0; i < content.length(); i++) {
            char ch = content.charAt(i);
            //if (this.isValidChar(ch)) {
                retStr = retStr + ch;
            //}
        }
        return retStr;
    }
    /** 驗證是否是字符 **/
    @SuppressWarnings("unused")
	private boolean isValidChar(char ch) {
        if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z')
                || (ch >= 'a' && ch <= 'z'))
            return true;
        if ((ch >= 0x4e00 && ch <= 0x9FA5) || (ch >= 0xF900 && ch <= 0xFA2D))
            return true;
        return false;
    }
 
    AtomicPattern(Pattern pattern) {
        this.pattern = pattern;
    };
 
    private Pattern pattern;
    public UnionPattern belongUnionPattern;
 
    public UnionPattern getBelongUnionPattern() {
        return belongUnionPattern;
    }
 
    public void setBelongUnionPattern(UnionPattern belongUnionPattern) {
        this.belongUnionPattern = belongUnionPattern;
    }
 
    public Pattern getPattern() {
        return pattern;
    }
 
    public void setPattern(Pattern pattern) {
        this.pattern = pattern;
    }
}
 
class SameAtomicPatternSet {
    SameAtomicPatternSet() {
        SAPS = new Vector<AtomicPattern>();
    };
 
    public Vector<AtomicPattern> SAPS;
}
 
class UnionPattern { // union string
    UnionPattern() {
        this.apSet = new Vector<AtomicPattern>();
    }
 
    public Vector<AtomicPattern> apSet;
 
    public void addNewAtomicPattrn(AtomicPattern ap) {
        this.apSet.add(ap);
    }
 
    public Vector<AtomicPattern> getSet() {
        return apSet;
    }
 
    public boolean isIncludeAllAp(Vector<AtomicPattern> inAps) {
        if (apSet.size() > inAps.size())
            return false;
        for (int i = 0; i < apSet.size(); i++) {
            AtomicPattern ap = apSet.get(i);
            if (isInAps(ap, inAps) == false)
                return false;
        }
        return true;
    }
 
    private boolean isInAps(AtomicPattern ap, Vector<AtomicPattern> inAps) {
        for (int i = 0; i < inAps.size(); i++) {
            AtomicPattern destAp = inAps.get(i);
            if (ap.getPattern().getStr().equalsIgnoreCase(destAp.getPattern().getStr()))
               return true;
        }
        return false;
    }
 
    public void setLevel(int level) {
        this.level = level;
    }
 
    public int getLevel() {
        return this.level;
    }
 
    private int level;
}
 
class UnionPatternSet { // union string set
    UnionPatternSet() {
        this.unionPatternSet = new Vector<UnionPattern>();
    }
 
    public void addNewUnionPattrn(UnionPattern up) {
        this.unionPatternSet.add(up);
    }
 
    public Vector<UnionPattern> unionPatternSet;
 
    public Vector<UnionPattern> getSet() {
        return unionPatternSet;
    }
 
    public void clear() {
        unionPatternSet.clear();
    }
}